package com.bj58.groupbuy.action.service.impl;

import java.util.List;

import com.bj58.groupbuy.action.db.CommonDao;
import com.bj58.groupbuy.action.db.DBConfig;
import com.bj58.groupbuy.action.model.UserSubMailVo;
import com.bj58.groupbuy.action.service.UserSubMailService;
import com.bj58.groupbuy.service.impl.BaseService;
import com.bj58.groupbuy.wf.page.Paginate;

public class UserSubMailServiceImpl extends BaseService<UserSubMailVo> implements UserSubMailService {
	private CommonDao comDao = new CommonDao();

	@Override
	public List<UserSubMailVo> getListByUserId(int userId) throws Exception {
		List<UserSubMailVo> rsList = getGenericDao().find(UserSubMailVo.class, "*", "userId="+userId, "id");
		if( null != rsList  && !rsList.isEmpty())
			return rsList;
		
		return null;
	}

	@Override
	public Paginate<UserSubMailVo> getSubListByPage(int pageIndex, int pageSize,
			String where) throws Exception {
		return getGenericDao().findForPage(UserSubMailVo.class, where, "*", pageIndex, pageSize, "id desc");
	}

	@Override
	public int updateVo(UserSubMailVo vo)throws Exception {
		return comDao.updateByVo("ir_downemail", "id="+vo.getId(), UserSubMailVo.class, vo, DBConfig.db_68_bi_sys.getIntType());
		
	}

	@Override
	public UserSubMailVo findOneById(int id) throws Exception {
		String searchSql = "select * from ir_downemail  where id= "+id;
		List<UserSubMailVo> rsList = comDao.getAllColsByVo(searchSql, UserSubMailVo.class, DBConfig.db_68_bi_sys.getIntType());
		if(rsList.isEmpty() || null == rsList){
			return null;
		}
		return rsList.get(0);
	}

	@Override
	public List<UserSubMailVo> getAllToSendList() throws Exception {
		List<UserSubMailVo> rsList = getGenericDao().find(UserSubMailVo.class, "*", "state=1", "id");
		if( null != rsList  && !rsList.isEmpty())
			return rsList;
		
		return null;
	}
}
